package com.wangxinyuchuan.demo.handler;

import com.wangxinyuchuan.demo.model.User;

public abstract class Handler {

    public Handler next;

    public void setNext(Handler next) {
        this.next = next;
    }

    public abstract void doHandler(User user);

    public static class Builder {

        private Handler head;

        private Handler tail;

        public Builder addHandler(Handler handler) {
            if (this.head == null) {
                this.head = handler;
                this.tail = handler;
                return this;
            }
            this.tail.setNext(handler);
            this.tail = handler;
            return this;
        }

        public Handler build() {
            return this.head;
        }
    }
}
